//获取应用实例
const app = getApp();
Page({
  data: {
    wximg: '',
    local: '',
    img: '',
    
    lvarr: '', //上传后的图片数组
    livurl: '', //上传后的图片路径
    propic: '', //上传到服务器后的图片路径
    // 组件所需的参数
    nvabarData: {
      showCapsule: 1, //是否显示左上角图标   1表示显示    0表示不显示
      title: '文档打印', //导航栏 中间的标题
    },
    // 此页面 页面内容距最顶部的距离
    height: app.globalData.height * 2 + 20,
  },
  onLoad() {
    
    let url = app.globalData.url+'facility/type/list'
    let data = {};
    app.wxRequest('GET', url, data, (res) => {
      console.log(res)
    })
  },
  gocharacter_speed: function () {
    wx.navigateTo({
      url: '/modelA/pages/documents_printing/character_speed/character_speed',
      success: function (res) {},
      fail: function (res) {},
      complete: function (res) {},
    })
  },
  // 上传微信文件
  wechat_file: function () {
    let that = this;
    let wximg = that.data.wximg;
    wx.chooseMessageFile({
      count: 1,
      type: 'file',
      success(res) {
        let tempFilePaths = res.tempFiles[0].path;
        console.log(tempFilePaths)
        wx.showLoading({
          title: '文件上传中',
          mask: true
        });
        let src = tempFilePaths;
        // 上传到服务器
        var key = Math.random().toString(36).substr(2); //生成一个随机字符串的文件名
        let url = app.globalData.URL + 'common/upload'
        wx.uploadFile({
          url: url,
          filePath: src,
          header: {
            "Content-Type": "multipart/form-data",
            'accept': 'application/json',
            'Authorization': app.globalData.token //若有token，此处换上你的token，没有的话省略
          },
          name: 'file',
          formData: {
            'key': key //这里是为文件设置上传后的文件名
          },
          success: function (res) {
            console.log(res)
            let lvarr = JSON.parse(res.data)
            that.setData({
              title:'微信文件打印',
              chicun:'A4',
              lvarr: lvarr,
              content: lvarr.url,
            })
            wx.hideLoading();
            console.log(that.data.propic)
            wx.navigateTo({
              url: '/modelA/pages/documents_printing/picplace_order/picplace_order?title=' + that.data.title + '&chicun=' + that.data.chicun+'&content='+that.data.content+'&id=14',
            })
          },
          fail: function (res) {}
        })
      }
    })

  },
  // 上传本地文件
  local_file: function () {
    wx.navigateTo({
      url: '/modelA/pages/documents_printing/wps/wps',
    })
  },
  // 上传到服务器
  unloadfwq(src) {
    let that = this;
    // 上传到服务器
    var key = Math.random().toString(36).substr(2); //生成一个随机字符串的文件名
    let url = app.globalData.URL + 'common/upload'
    wx.uploadFile({
      url: url,
      filePath: src,
      header: {
        "Content-Type": "multipart/form-data",
        'accept': 'application/json',
        'Authorization': app.globalData.token 
      },
      name: 'file',
      formData: {
        'key': key //这里是为文件设置上传后的文件名
      },
      success: function (res) {
        console.log(res)
        let lvarr = JSON.parse(res.data)
        that.setData({
          lvarr: lvarr,
          livurl: lvarr.url,
          propic: lvarr.url,
        })

        console.log(lvarr, lvarr.url)
        let livurl = lvarr.url;
      },
      fail: function (res) {
        console.log(res)
      }
    })
  },
  // // 上传本地图片
  // tel_phonimg: function () {
  //   let that = this;
  //   let img = that.data.img;
  //   wx.chooseImage({
  //     count: 1,
  //     sizeType: ['original', 'compressed'],
  //     sourceType: ['album', 'camera'],
  //     success(res) {
  //       // tempFilePath可以作为img标签的src属性显示图片
  //       console.log(res.tempFilePaths[0])
  //       that.setData({
  //         img: res.tempFilePaths[0]
  //       })
  //       let src = res.tempFilePaths[0];
  //       console.log(src)
  //       that.unloadfwq(src);
  //       setTimeout(function () {
  //         let title = '手机图片打印';
  //         let chicun = '2100mm*2970mm';
  //         let content = that.data.propic;
  //         wx.navigateTo({
  //           url: '/modelA/pages/documents_printing/picplace_order/picplace_order?title=' + title + '&chicun=' + chicun+'&content='+content+'&id=12',
  //         })
  //       }, 3000)
  //     }
  //   })
    
  // },

})